<?php

namespace Biz\model\wiki;


class WikiBuyModel extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'store';

    const _TABLE_NAME = 'wiki_buy';

    const STATUS_NORMAL = 1;//正常
    const STATUS_DEL = 9;//删除


    public static function selectByWhere($where, $field = '*')
    {
        return self::select($field, $where);
    }

    public static function getUserWikiCount($uid)
    {
        return self::count(['uid' => $uid, 'status' => self::STATUS_NORMAL]);
    }
    public static function getByUid($where , $filed = '*' )
    {
        return self::get($filed , $where);
    }

    public static function insertData($data)
    {
        if (!isset($data['addtime'])) {
            $data['addtime'] = date('Y-m-d H:i:s');
        }
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }

        return self::id();
    }


    public static function updateData($data, $where)
    {
        if (!isset($data['edittime']) || !$data['edittime']) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }

        return self::update($data, $where)->rowCount();
    }

    public static function getStatus($uid, $wikiId)
    {
        return self::get('status', [
                'uid' => $uid,
                'wiki_id' => $wikiId,
            ]) ?? 0;
    }


}